/******************************************************************
* Copyright (C), 2005-2007, HISILICON Tech. Co., Ltd.             *
*                                                                 *
* File name: sys.h                                                *
*                                                                 *
* Description:                                                    *
*       define general funtion for system designing               *
*                                                                 *
* Author:                                                         *
*     Sunshaojie(62494)                                           *
* Version: v1.0                                                   *
*                                                                 *
* Function List:                                                  *
*                                                                 *
* Date:                                                           *
*                                                                 *
* History:                                                        *
*                                                                 *
*******************************************************************/
#ifndef SYS_H
#define SYS_H

#define NULL    (void *)0

#define TRUE    1
#define FALSE   0

#define ERROR         -1
#define OK            0

#define BIT0    0x0001
#define BIT1    0x0002
#define BIT2    0x0004
#define BIT3    0x0008
#define BIT4    0x0010
#define BIT5    0x0020
#define BIT6    0x0040
#define BIT7    0x0080
#define BIT8    0x0100
#define BIT9    0x0200
#define BIT10   0x0400
#define BIT11   0x0800
#define BIT12   0x1000
#define BIT13   0x2000
#define BIT14   0x4000
#define BIT15   0x8000

typedef unsigned char 	UINT8, UCHAR, BYTE, *PUINT8, *PUCHAR, *PBYTE, *LPBYTE;
typedef unsigned short 	UINT16, USHORT, WORD, *PUINT16, *PUSHORT, *PWORD;
typedef unsigned long 	UINT32, ULONG, DWORD, *PUINT32, *PULONG, *PDWORD;
typedef char 	INT8, CHAR, TCHAR, *PINT8, *PTCHAR, *PCHAR;
typedef short 	INT16, SHORT, *PINT16;
typedef long	INT32, BOOL, STATUS, LONG, *PINT32;
typedef double 	DOUBLE, LONGLONG;

typedef const CHAR  	*LPCSTR;

typedef void 	VOID, *PVOID, *HANDLE;
typedef HANDLE 	*PHANDLE;

#define CONST 	const

typedef union 	_LARGE_INTEGER
{
    struct
    {
        DWORD LowPart;
        LONG HighPart;
    };
    struct
    {
        DWORD LowPart;
        LONG HighPart;
    }u;
    LONGLONG QuadPart;
} LARGE_INTEGER;
typedef LARGE_INTEGER PHYSICAL_ADDRESS, *PPHYSICAL_ADDRESS;

#ifndef min
#define min(a,b)        ((a)<(b)?(a):(b))
#endif

#ifndef max
#define max(a,b)        ((a)>(b)?(a):(b))
#endif

/* register control */
#define READ_REGISTER_UCHAR(addr) (*(volatile UINT8 *)(addr))
#define READ_REGISTER_USHORT(addr) (*(volatile UINT16 *)(addr))
#define READ_REGISTER_ULONG(addr) (*(volatile UINT32 *)(addr))

#define WRITE_REGISTER_UCHAR(addr,val) (*(volatile UINT8 *)(addr) = (val))
#define WRITE_REGISTER_USHORT(addr,val) (*(volatile UINT16 *)(addr) = (val))
#define WRITE_REGISTER_ULONG(addr,val) (*(volatile UINT32 *)(addr) = (val))

#define INREG8(x)           READ_REGISTER_UCHAR(x)
#define OUTREG8(x, y)       WRITE_REGISTER_UCHAR(x, (UINT8)(y))
#define SETREG8(x, y)       OUTREG8(x, INREG8(x)|(y))
#define CLRREG8(x, y)       OUTREG8(x, INREG8(x)&~(y))
#define SETBITVALUE8(addr, mask, value) \
                OUTREG8(addr, (INREG8(addr)&(~mask)) | (value&mask))

#define INREG16(x)          READ_REGISTER_USHORT(x)
#define OUTREG16(x, y)      WRITE_REGISTER_USHORT(x,(UINT16)(y))
#define SETREG16(x, y)      OUTREG16(x, INREG16(x)|(y))
#define CLRREG16(x, y)      OUTREG16(x, INREG16(x)&~(y))
#define SETBITVALUE16(addr, mask, value) \
                OUTREG16(addr, (INREG16(addr)&(~mask)) | (value&mask))

#define INREG32(x)          READ_REGISTER_ULONG(x)
#define OUTREG32(x, y)      WRITE_REGISTER_ULONG(x, (UINT32)(y))
#define SETREG32(x, y)      OUTREG32(x, INREG32(x)|(y))
#define CLRREG32(x, y)      OUTREG32(x, INREG32(x)&~(y))
#define SETBITVALUE32(addr, mask, value) \
                OUTREG32(addr, (INREG32(addr)&(~mask)) | (value&mask))




#define FOREVER         while(1)
//#define inline
#define IN
#define OUT

#endif
